<html>
    <script language="javascript" type="text/javascript" src="http://people.iola.dk/olau/flot/examples/../jquery.js"></script> 
    <script type="text/javascript">
        var ws = new WebSocket("ws://localhost:9999 ");

        ws.onopen = function() {
            demoinstr=["os.listdir('.')",
                       "os.path.isdir('.')",
                       "os.path.exists('foo.txt')",
                       "pylab.savetxt('new.txt',['Your random number is: "+Math.floor(Math.random()*100)+"'],'%s')",
                       "pylab.loadtxt('new.txt','str',delimiter='\\n')",
                       "os.path.isfile('new.txt')"
                       ];
            
            $.each(demoinstr, function(index, value) { 
                instr=value;
                idot=instr.indexOf('.');
                ipar=instr.indexOf('(');
                fcn=instr.substr(idot+1, ipar-idot-1).replace('.','');
                $("body").append("<div id='"+fcn+"'><h2>"+instr+"</h2></div>");
                ws.send(instr);
            });
        }; 
        ws.onmessage = function (e) {
            eval(e.data)
        };  
        window.onbeforeunload = function() {
            ws.send("DISCONNECTED");
            ws.onclose = function () {};
            ws.close()
        };
        
        var True=true;
        var False=false;
           
        pylab=new function() {
            this.loadtxt=function(l) {
                $("#loadtxt").append(l.toString()+'<br/>');
            }
            this.savetxt=function(l) {
            }
        }
        
        os=new function() {
            this.listdir=function(l) {
                $.each(l, function(index, value) { 
                       $("#listdir").append(value.toString()+'<br/>');
                       });
            }
            this.path=new function(){
                this.exists=function(r) {
                    $("#pathexists").append(r.toString());
                }
                this.isdir=function(r) {
                    $("#pathisdir").append(r.toString());
                }
                this.isfile=function(r) {
                    $("#pathisfile").append(r.toString());
                }
            }
        }
        
        sys=new function() {
            this.exception=function(msg) {
                $("body").append("<div>"+msg.toString()+"</div>");
            }
        }
        
    </script>
    <body>
        <div><h1>PyWIO Demo</h1></div>
    </body>
</html>